﻿using ImperialUtilities.Utilities;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services;

namespace ImperialWebService
{
    /// <summary>
    /// Summary description for ImperialWebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class ImperialWebService : System.Web.Services.WebService
    {
        private const string TAB = "\t";
        private EventViewer _logger = new EventViewer("ImperialWebService");

        [WebMethod]
        public bool RegisterJediFile(string username, string realname, string roleName, string specieName, string statusName)
        {
            bool isValid = false;
            StringBuilder builder = new StringBuilder();
            try
            {
                builder.Append(username);
                builder.Append(TAB);
                builder.Append(realname);
                builder.Append(TAB);
                builder.Append(roleName);
                builder.Append(TAB);
                builder.Append(specieName);
                builder.Append(TAB);
                builder.Append(statusName);
                builder.Append(TAB);
                builder.Append(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"));

                using (System.IO.StreamWriter file = new System.IO.StreamWriter(ConfigurationManager.AppSettings["filePath"].ToString(), true))
                {
                    file.WriteLine(builder.ToString());
                    isValid = true;
                }
            }
            catch (Exception e)
            {
                _logger.WriteEventViewerLog("RegisterJediFile", e.Message, true);
                isValid = false;
            }
            return isValid;
        }
    }
}
